<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.DriverManager" %><%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2018/4/3
  Time: 17:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>更新数据</title>
</head>
<body>
<%

    //得到用户输入信息
    String id = request.getParameter("id");
    String username = request.getParameter("name");
    String password = request.getParameter("psd");
%>
<a href="userList.jsp">返回列表</a>

<form action="#" method="post">
    <input type="text" name="id" value="<%=id%>" hidden="hidden">
    用户名：<input type="text" name="username" value="<%=username%>"></br>
    密码：  <input type="text" name="password" value="<%=password%>"></br>
    <input type="submit" value="更新">
</form>
<%
     request.setCharacterEncoding("UTF-8");
     username = request.getParameter("username");
     password = request.getParameter("password");

    Connection connection = null;
    Statement statement = null;
    ResultSet resultSet = null;

    String sql = "UPDATA t_users SET id = ?,username =?,password = ?,WHERE id =?";

    Class.forName("com.mysql.jdbc.Driver");
    connection = DriverManager.getConnection(
            "jdbc:mysql://localhost:3306/sctu_javaweb_2018?serverTimezone=UTC",
            "root",
            "113223"
    );
    statement = connection.createStatement();
    statement.executeUpdate("UPDATE t_users set username='"+username+"'," +
            "password ='"+password+"' WHERE id='"+id+"'");

    statement.close();
    connection.close();

%>
</body>
//加入版权信息并获取年份
<%--
<jsp:include page="footer.jsp">
    <jsp: name="year" value="2018">
        </jsp:include>
--%>
</html>
